package com.unionpay.util

import java.io.File

import com.typesafe.config.{Config, ConfigFactory}
import net.ceedubs.ficus.Ficus._
import net.ceedubs.ficus.readers.ValueReader

object ConfigUtil {

  /**
    * 读取配置文件
    *
    * @param path
    * @param root
    * @tparam T
    * @return
    */
  def readFileConfig[T: ValueReader](path: String, root: String = "task") = {
    val myConfigFile = new File(path)
    val fileConfig = ConfigFactory.parseFile(myConfigFile)
    val config: Config = ConfigFactory.load(fileConfig)
    val tasks = config.as[T](root)
    tasks
  }

  /**
    *
    * @param configFileName
    * @param root
    * @tparam T
    * @return
    */

  def readClassPathConfig[T: ValueReader](configFileName: String, root: String = "task") = {
    val config: Config = ConfigFactory.load(configFileName)
    val tasks = config.as[T](root)
    tasks
  }

}
